<template>
	<view class="goods-item" @click="onGoodsItemClicked">
		<view class="goods-cover">
			<view class="checked-show" v-if="showRadio">
				<label class="radio">
					<radio value="r1" :checked="item.goods_state" color="#C00000" @click="onRadioClick"/>
				</label>
			</view>
			<image :src="item.goods_small_logo || defaultImage"></image>
		</view>
		<view class="goods-desc">
			<view class="goods-name">
				{{ item.goods_name }}
			</view>
			<view class="goods-footer">
				<view class="goods-price">
					{{ item.goods_price | priceFormat }}
				</view>
				<view class="goods-num-box" v-if="showNumberBox">
					<uni-number-box :value="item.goods_count" :min="1" @change="onNumberChange"></uni-number-box>
				</view>
			</view>
		</view>
	</view>
</template>

<script>
	export default {
		name: "GoodsItem",
		props: {
			item: {
				type: Object,
				default: () => {}
			},
			showRadio: {
				type: Boolean,
				default: false
			},
			showNumberBox: {
				type: Boolean,
				default: false
			}
		},
		data() {
			return {
				defaultImage: 'https://img3.doubanio.com/f/movie/8dd0c794499fe925ae2ae89ee30cd225750457b4/pics/movie/celebrity-default-medium.png',
			};
		},
		methods: {
			onGoodsItemClicked() {
				this.$emit('onGoodsItemClicked')
			},
			onRadioClick() {
				const goods = {
					goods_id: this.item.goods_id,
					goods_state:!this.item.goods_state
				}

				this.$emit('radioChange',goods)
			},
			onNumberChange(value) {
				const goods = {
					goods_id: this.item.goods_id,
					goods_count: value
				}
				this.$emit('number-change',goods)
			}
		}
	}
</script>

<style lang="scss">
	.goods-item {
		display: flex;
		border-bottom: 1px solid #f0f2f5;
		margin-top: 12rpx;

		.goods-cover {
			display: flex;
			align-items: center;
			padding-left: 16rpx;
			justify-content: space-between;
			image {
				width: 100px;
				height: 100px;
				border-radius: 16rpx;
			}
		}

		.goods-desc {
			display: flex;
			flex-direction: column;
			justify-content: space-between;
			padding: 12rpx;
			margin-left: 24rpx;

			.goods-name {
				font-size: 26rpx;
			}
			
			.goods-footer {
				display: flex;
				justify-content: space-between;
				.goods-price {
					font-size: 36rpx;
					font-weight: 700;
					color: #E4393C;
				}
			}

		}
	}
</style>
